#include "MoveAnimator.h"
#include "../../include/ISceneNode.h"

CMoveAnimator::CMoveAnimator(vector3dvpos &PositionIni,vector3dvpos &PositionFin,u32 Time):PosIni(PositionIni),PosFin(PositionFin),
TimeToWork(Time),TimeBegin(0)
{
}

CMoveAnimator::~CMoveAnimator()
{

}

bool CMoveAnimator::AnimateNode(u32 Time,ISceneNode *Node)
{
	if (!TimeBegin)
		TimeBegin = Time;

	Elapsed = Time - TimeBegin;

    vPos Alpha = 0;
	if (Elapsed)
		Alpha = (vPos)((vPos)Elapsed) / ((vPos)TimeToWork);

    if (Elapsed <= TimeToWork)
    {
        Node->SetPosition(PosIni.X + ((PosFin.X - PosIni.X) * Alpha),
			PosIni.Y + ((PosFin.Y - PosIni.Y) * Alpha),
			PosIni.Z + ((PosFin.Z - PosIni.Z) * Alpha));
	}

	if (Elapsed >= TimeToWork)
	{
		Node->SetPosition(PosFin);
		return true;
	}
	else
		return false;
}
